package com.web.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.web.dao.SysPosterDao;
import com.web.entity.SysPoster;
import com.web.entity.SysUser;
import com.web.service.SysPosterService;

@Service
public class SysPosterServiceImpl implements SysPosterService {

	@Autowired
	private SysPosterDao sysPosterDao;

	@Override
	public List<SysPoster> selectPoster() {
		// Map<String, Object> map=new HashMap<String, Object>();
		// [Obj,Obj] data.result
		// map.put("result","yes");
		return sysPosterDao.findAllPoster();
	}

	@Override
	public PageInfo selectAllPoster(SysPoster sp, Integer pageNum, Integer pageSize) {
		PageHelper.startPage(pageNum, pageSize); // 调用分页功能
		List<SysPoster> list = sysPosterDao.getAllPoster(sp); // 上面的分页会自动注入到本条查询中
		System.out.println(JSONObject.toJSON(list));
		PageInfo<SysPoster> pageInfo = new PageInfo<SysPoster>(list); // 获取分页信息
		System.out.println(JSONObject.toJSON(pageInfo));
		return pageInfo;
	}

	@Override
	public Map<String, Object> changePosterState(Integer id, Integer state) {
		Map<String, Object> map = new HashMap<String, Object>();
		sysPosterDao.updatePosterState(id, state);
		map.put("result", 1);
		return map;
	}

	@Override
	public Map<String, Object> addPoster(SysPoster sysPoster) {
		sysPosterDao.addPoster(sysPoster);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("result", "success");
		return map;
	}

	@Override
	public Map<String, Object> delRowPoster(Integer id) {
		Map<String, Object> map = new HashMap<String, Object>();
		sysPosterDao.delPoster(id);
		map.put("result", 1);
		return map;
	}

	@Override
	public List<SysPoster> getIdPoster(Integer id) {

		return sysPosterDao.getIdPoster(id);
	}

	@Override
	public Map<String, Object> changePoster(Integer id, String name, String path, Integer state, String remark) {
		Map<String, Object> map = new HashMap<String, Object>();
		sysPosterDao.updategetIDPoster(id, name, path, state, remark);
		map.put("result", 1);
		return map;
	}

}
